home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / std / c / 326 < prev    next >
Internet Message Format  |  1996-08-06  |  4KB

  1. Path: tko.dec.com!diamond
  2. From: diamond@tko.dec.com (Norman Diamond)
  3. Newsgroups: comp.std.c
  4. Subject: Re: Binary Mode stdin/stdout
  5. Date: 8 Feb 1996 02:40:35 GMT
  6. Organization: Digital Equipment Corporation Japan , Tokyo
  7. Message-ID: <4fbnr3$veg@usenet.pa.dec.com>
  8. References: <4f67kg$11g@cortex.dialin.rrze.uni-erlangen.de> <DME74w.4M4@stdc.demon.co.uk>
  9. Reply-To: diamond@jrdv04.enet.dec-j.co.jp (Norman Diamond)
  10. NNTP-Posting-Host: jit533.tko.dec.com
  11.  
  12. In article <DME74w.4M4@stdc.demon.co.uk>, clive@stdc.demon.co.uk (Clive D.W. Feather) writes:
  13. >In article <4f67kg$11g@cortex.dialin.rrze.uni-erlangen.de>,
  14. >Markus Kuhn <mskuhn@cip.informatik.uni-erlangen.de> wrote:
  15. >> Why isn't there a standard way of allowing an ISO C program to switch
  16. >> the standard input and output into binary transparent mode (as with
  17. >> the "b" flag in fopen()/freopen() for normal files)?
  18.  
  19. >On some implementations, this decision has to be made at the time you
  20. >open the file and can't be changed.
  21.  
  22. I'll take your word for it.  I suppose the operating system would require
  23. the program to close the file and reopen it, so that is what the C standard
  24. requires the C program to do.  (This is also why the C standard requires C
  25. programs to simulate long int arithmetic on their own instead of building
  26. it into the language, since some hardware doesn't have it, right?)
  27.  
  28. >For example, on OS/360 and its successors, text files might be VB80,
  29. >while binary files will be U508, or whatever. The former is stored as:
  30. >    <4 byte value N1> <N1 bytes of text forming a line>
  31. >    <4 byte value N2> <N1 bytes of text forming a line>
  32. >    <4 byte value N3> <N1 bytes of text forming a line>
  33.  
  34. Close...
  35.      <4 byte block length, max. value 80>
  36.      <4 byte value N1> <N1 bytes of text forming a line>
  37.      <4 byte value N2> <N2 bytes of text forming a line>
  38.      <4 byte value N3> <N3 bytes of text forming a line>
  39. Actually I have a vague recollection that the counts are recorded
  40. as 4+N1, 4+N2, and 4+N3 (i.e. their lengths include themselves).
  41.  
  42. >(note that there are no newline characters) and the latter as
  43. >    <4 byte value N1> <N1 bytes of data> <508-N1 bytes ignored>
  44. >    <4 byte value N2> <N1 bytes of data> <508-N1 bytes ignored>
  45. >    <4 byte value N3> <N1 bytes of data> <508-N1 bytes ignored>
  46. >(data is read and written in 512 byte units).
  47.  
  48. Not so close this time.  Only the data are recorded, max. 508 bytes per line:
  49.      <N1 bytes of data>
  50.      <N2 bytes of data>
  51.      <N3 bytes of data>
  52. Though again there is no recording of newline characters.
  53.  
  54. >How do you switch these ?
  55.  
  56. By storing the desired form of reading into the RECFM field of the DCB
  57. before doing the read.  If a file was written using format VB80 and read
  58. back using format VB80 then you see each line as it was written.  If a
  59. file was written using format VB80 and read back using format U508 then
  60. you see the actual recorded form of each block, and you get to break it
  61. up yourself or not as you wish.  If a file was written using format U508
  62. and read back using format VB80, then either you had to be very careful
  63. to write something that conforms to VB80 or else behavior would probably
  64. be undefined.
  65.  
  66. However, I'll take your word for it that C has been implemented on less
  67. cooperative operating systems.
  68. --
  69.  <<  If this were the company's opinion, I would not be allowed to post it.  >>
  70. "I paid money for this car, I pay taxes for vehicle registration and a driver's
  71. license, so I can drive in any lane I want, and no innocent victim gets to call
  72. the cops just 'cause the lane's not goin' the same direction as me" - J Spammer
  73.